﻿using System;
using fastCSharp;

namespace diantou.web
{
    /// <summary>
    /// 搜索结果
    /// </summary>
    [fastCSharp.code.cSharp.webView(IsPage = false, IsPool = true, IsReferer = false)]
    partial class search : view<search>
    {
        /// <summary>
        /// 用户相关搜索结果项
        /// </summary>
        private struct userSearch
        {
            /// <summary>
            /// 搜索结果项
            /// </summary>
            public diantou.dataAccess.searchItem Item;
            /// <summary>
            /// 用户标识
            /// </summary>
            public int UserId;
            /// <summary>
            /// 用户问题关系
            /// </summary>
            public question.userQuestion UserQuestion
            {
                get { return new question.userQuestion { Question = Item.Question, UserId = UserId }; }
            }
            /// <summary>
            /// 用户收藏关系
            /// </summary>
            public favorite.userFavorite UserFavorite
            {
                get { return new favorite.userFavorite { Favorite = Item.Favorite, UserId = UserId }; }
            }
            /// <summary>
            /// 用户话题关系
            /// </summary>
            public topic.userTopic UserTopic
            {
                get { return new topic.userTopic { Topic = Item.LinkTopic ?? Item.Topic, UserId = UserId }; }
            }
            /// <summary>
            /// 用户关系
            /// </summary>
            public user.userRelation UserRelation
            {
                get { return new user.userRelation { User = Item.User, UserId = UserId }; }
            }
        }
        /// <summary>
        /// 搜索结果集合
        /// </summary>
        [fastCSharp.emit.webView.clearMember]
        private userSearch[] results;
        /// <summary>
        /// 最新动态
        /// </summary>
        /// <param name="page">分页号</param>
        /// <returns>是否成功</returns>
        private bool loadView(string key, int page, diantou.dataAccess.search.type type)
        {
            if ((key = include.search.FormatKey(key)).length() != 0)
            {
                bool isTopic = false;
                diantou.dataAccess.searchItem[] values = diantou.dataAccess.tcpCall.searchItem.get(new dataAccess.searchInfo { Keyword = key, Type = type, PageSize = pageInfo.Size = fastCSharp.config.pub.Default.PageSize, Page = pageInfo.Page = page }, currentUserId, false, out pageInfo.Count, ref isTopic);
                results = values.getArray(value => new userSearch { Item = value, UserId = currentUserId });
            }
            return true;
        }
    }
}
